package com.qdc.datacenters.controller;

import com.github.pagehelper.PageInfo;
import com.qdc.datacenters.annotation.Log;
import com.qdc.datacenters.domain.ResponseResult;
import com.qdc.datacenters.domain.query.statistics.StatisticsQuery;
import com.qdc.datacenters.domain.query.statistics.TimeoutStatisticsQuery;
import com.qdc.datacenters.domain.vo.statistics.*;
import com.qdc.datacenters.enums.BusinessTypeEnum;
import com.qdc.datacenters.service.ChatMsgStatisticsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author danmo
 * @date 2024-03-20 10:09
 **/
@Tag(name = "数据分析")
@RestController
@RequestMapping("/statistics")
public class ChatMsgStatisticsController extends BaseController {


    @Autowired
    private ChatMsgStatisticsService chatMsgStatisticsService;


    @Log(title = "单聊员工敏感词排行", businessType = BusinessTypeEnum.SELECT)
    @PreAuthorize("@authz.hasPerm('statistics:sensitive:single:user:rank')")
    @Operation(summary = "单聊员工敏感词排行", method = "POST")
    @PostMapping("/sensitive/single/user/rank")
    public ResponseResult<PageInfo<SensitiveUserRankVo>> sensitiveSingleUserRank(@RequestBody StatisticsQuery query) {
        startPage(query.getPageIndex(), query.getPageSize(), query.getSortField(), query.getSort());
        List<SensitiveUserRankVo> list = chatMsgStatisticsService.sensitiveSingleUserRank(query);
        PageInfo<SensitiveUserRankVo> pageInfo = new PageInfo<>(list);
        return ResponseResult.success(pageInfo);
    }

    @Log(title = "单聊客户敏感词排行", businessType = BusinessTypeEnum.SELECT)
    @PreAuthorize("@authz.hasPerm('statistics:sensitive:single:customer:rank')")
    @Operation(summary = "单聊客户敏感词排行", method = "POST")
    @PostMapping("/sensitive/single/customer/rank")
    public ResponseResult<PageInfo<SensitiveCustomerRankVo>> sensitiveSingleCustomerRank(@RequestBody StatisticsQuery query) {
        startPage(query.getPageIndex(), query.getPageSize(), query.getSortField(), query.getSort());
        List<SensitiveCustomerRankVo> list = chatMsgStatisticsService.sensitiveSingleCustomerRank(query);
        PageInfo<SensitiveCustomerRankVo> pageInfo = new PageInfo<>(list);
        return ResponseResult.success(pageInfo);
    }

    @Log(title = "群聊员工敏感词排行", businessType = BusinessTypeEnum.SELECT)
    @PreAuthorize("@authz.hasPerm('statistics:sensitive:group:user:rank')")
    @Operation(summary = "群聊员工敏感词排行", method = "POST")
    @PostMapping("/sensitive/group/user/rank")
    public ResponseResult<PageInfo<SensitiveUserRankVo>> sensitiveGroupUserRank(@RequestBody StatisticsQuery query) {
        startPage(query.getPageIndex(), query.getPageSize(), query.getSortField(), query.getSort());
        List<SensitiveUserRankVo> list = chatMsgStatisticsService.sensitiveGroupUserRank(query);
        PageInfo<SensitiveUserRankVo> pageInfo = new PageInfo<>(list);
        return ResponseResult.success(pageInfo);
    }

    @Log(title = "群聊客户敏感词排行", businessType = BusinessTypeEnum.SELECT)
    @PreAuthorize("@authz.hasPerm('statistics:sensitive:group:customer:rank')")
    @Operation(summary = "群聊客户敏感词排行", method = "POST")
    @PostMapping("/sensitive/group/customer/rank")
    public ResponseResult<PageInfo<SensitiveCustomerRankVo>> sensitiveGroupCustomerRank(@RequestBody StatisticsQuery query) {
        startPage(query.getPageIndex(), query.getPageSize(), query.getSortField(), query.getSort());
        List<SensitiveCustomerRankVo> list = chatMsgStatisticsService.sensitiveGroupCustomerRank(query);
        PageInfo<SensitiveCustomerRankVo> pageInfo = new PageInfo<>(list);
        return ResponseResult.success(pageInfo);
    }

    @Log(title = "敏感词规则统计", businessType = BusinessTypeEnum.SELECT)
    @PreAuthorize("@authz.hasPerm('statistics:sensitive:list')")
    @Operation(summary = "敏感词规则统计", method = "POST")
    @PostMapping("/sensitive/list")
    public ResponseResult<PageInfo<SensitiveStatisticsListVo>> sensitiveStatistic(@RequestBody StatisticsQuery query) {
        startPage(query.getPageIndex(), query.getPageSize(), query.getSortField(), query.getSort());
        List<SensitiveStatisticsListVo> list = chatMsgStatisticsService.sensitiveStatistic(query);
        PageInfo<SensitiveStatisticsListVo> pageInfo = new PageInfo<>(list);
        return ResponseResult.success(pageInfo);
    }

    @Log(title = "单聊超时排行", businessType = BusinessTypeEnum.SELECT)
    @PreAuthorize("@authz.hasPerm('statistics:timeout:single:rank')")
    @Operation(summary = "单聊超时排行", method = "POST")
    @PostMapping("/timeout/single/rank")
    public ResponseResult<PageInfo<SingleTimeoutRankVo>> singleTimeoutRank(@RequestBody StatisticsQuery query) {
        startPage(query.getPageIndex(), query.getPageSize(), query.getSortField(), query.getSort());
        List<SingleTimeoutRankVo> list = chatMsgStatisticsService.singleTimeoutRank(query);
        PageInfo<SingleTimeoutRankVo> pageInfo = new PageInfo<>(list);
        return ResponseResult.success(pageInfo);
    }

    @Log(title = "群聊超时排行", businessType = BusinessTypeEnum.SELECT)
    @PreAuthorize("@authz.hasPerm('statistics:timeout:group:rank')")
    @Operation(summary = "群聊超时排行", method = "POST")
    @PostMapping("/timeout/group/rank")
    public ResponseResult<PageInfo<GroupTimeoutRankVo>> groupTimeoutRank(@RequestBody StatisticsQuery query) {
        startPage(query.getPageIndex(), query.getPageSize(), query.getSortField(), query.getSort());
        List<GroupTimeoutRankVo> list = chatMsgStatisticsService.groupTimeoutRank(query);
        PageInfo<GroupTimeoutRankVo> pageInfo = new PageInfo<>(list);
        return ResponseResult.success(pageInfo);
    }

    @Log(title = "超时规则统计", businessType = BusinessTypeEnum.SELECT)
    @PreAuthorize("@authz.hasPerm('statistics:timeout:list')")
    @Operation(summary = "超时规则统计", method = "POST")
    @PostMapping("/timeout/list")
    public ResponseResult<PageInfo<TimeoutStatisticsListVo>> timeoutStatistic(@RequestBody TimeoutStatisticsQuery query) {
        startPage(query.getPageIndex(), query.getPageSize(), query.getSortField(), query.getSort());
        List<TimeoutStatisticsListVo> list = chatMsgStatisticsService.timeoutStatistic(query);
        PageInfo<TimeoutStatisticsListVo> pageInfo = new PageInfo<>(list);
        return ResponseResult.success(pageInfo);
    }
}
